package com.augurit.gzcgwsp.smartformCsdlwj.convert;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.gzcgwsp.lhsp.web.form.LhspSendItemNoticeForm;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwSrCsdlwjForFx;
import com.augurit.gzcgwsp.smartformCsdlwj.entity.YwSrCsdlwj;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.CsdlwjForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxTwoForm;

/**
 * 道路挖掘
 * @author Administrator
 *
 */

public class YwSrCsdlwjConvertor {
    public static CsdlwjForm convertVoToForm(YwSrCsdlwj entity) {
        if (entity == null) return null;
        CsdlwjForm form = new DozerBeanMapper().map(entity, CsdlwjForm.class);        
        return form;
    }
	
	public static void convertSendItemNoticeFormToForm(LhspSendItemNoticeForm sendItemNoticeForm,CsdlwjForm form) {
        Long id = form.getId();
		new DozerBeanMapper().map(sendItemNoticeForm, form);
		form.setId(id);
    }

    //转换到建设单位form
    public static void convertFormToQyxxForm(CsdlwjForm form, YwComQyxxForm qyxxForm) {
        if (form == null) return;
        if (qyxxForm == null) qyxxForm = new YwComQyxxForm();

        new DozerBeanMapper().map(form, qyxxForm);
        if(StringUtils.isNotBlank(form.getQybh())){
        	qyxxForm.setId(Long.parseLong(form.getQybh()));
        }
    }
    //转换到施工单位form
    public static void convertFormToQyxxTwoForm(CsdlwjForm form, YwComQyxxTwoForm qyxxTwoForm) {
        if (form == null) return;
        if (qyxxTwoForm == null) qyxxTwoForm = new YwComQyxxTwoForm();
        if(StringUtils.isNotBlank(form.getQybhTwo())){
        	qyxxTwoForm.setId(Long.parseLong(form.getQybhTwo()));
        }
        if(StringUtils.isNotBlank(form.getAqfzr())){
        	qyxxTwoForm.setAqfzrTwo(form.getAqfzr());
        }
        if(StringUtils.isNotBlank(form.getSgdwAddress())){
        	qyxxTwoForm.setAddressTwo(form.getSgdwAddress());
        }
        if(StringUtils.isNotBlank(form.getSgdwTel())){
        	qyxxTwoForm.setTelTwo(form.getSgdwTel());
        }
        if(StringUtils.isNotBlank(form.getSgdwLxr())){
        	qyxxTwoForm.setLxrTwo(form.getSgdwLxr());
        }
    }

    public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, CsdlwjForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new CsdlwjForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQybh(qyxxForm.getId().toString());
    }
    
    public static void convertFormToVo(CsdlwjForm form, YwSrCsdlwj entity) {
        if (form == null) return;
        if (entity == null) entity = new YwSrCsdlwj();
        
        new DozerBeanMapper().map(form, entity);
    }
    
    public static List<CsdlwjForm> convertVoListToFormList(List<YwSrCsdlwj> ywSrCsdlwjList) {
        if(ywSrCsdlwjList != null && ywSrCsdlwjList.size() > 0) {
            List<CsdlwjForm> csdlwjFormList = new ArrayList();
            for(int i=0; i<ywSrCsdlwjList.size(); i++) {
            	csdlwjFormList.add(convertVoToForm(ywSrCsdlwjList.get(i)));
            }
            return csdlwjFormList;
        }
        return null;
    }
    
    public static List<YwSrCsdlwj> convertFormListToVoList(List<CsdlwjForm> csdlwjFormList) {
        if(csdlwjFormList != null && csdlwjFormList.size() > 0) {
            List<YwSrCsdlwj> ywSrCsdlwjList = new ArrayList();
            for(int i=0; i<csdlwjFormList.size(); i++) {
                YwSrCsdlwj ywSrCsdlwj = new YwSrCsdlwj();
                convertFormToVo(csdlwjFormList.get(i), ywSrCsdlwj);
                ywSrCsdlwjList.add(ywSrCsdlwj);
            }
            return ywSrCsdlwjList;
        }
        return null;
    }
    
    public static void convertFormToYwSrCsdlwjForFx(CsdlwjForm form, YwSrCsdlwjForFx entity) {
        if (form == null) return;
        if (entity == null) entity = new YwSrCsdlwjForFx();        
        new DozerBeanMapper().map(form, entity);
    }
}